package com.company.regist.servlet;

import com.company.regist.pojo.Register;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.company.regist.dao.IRegisterDAO;
import com.company.regist.dao.RegisterDAOImpl;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/insertregistercheck")
public class InsertRegisterCheckServlet extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		// HttpServletRequest req 
		// Tomcat自动创建的对象，会把用户的请求信息放入
		
//		HttpServletResponse resp
		// Tomcat自动创建的对象, 通过它给用户发信息
		
		// 1. 获取用户提交的参数
		String username = req.getParameter("username");
		String password = req.getParameter("password1");

		String sex = req.getParameter("sex");
		String marry = req.getParameter("marry");
		String birthday = req.getParameter("birthday");
		String tel = req.getParameter("tel");
		String qq = req.getParameter("qq");
		String age = req.getParameter("age");
		int intAge=Integer.parseInt(age);
		String deu = req.getParameter("deu");
		String like = req.getParameter("like");
		String intro = req.getParameter("intro");

		Register register=new Register(username,password,sex,marry,birthday,tel,qq,intAge,like,deu,intro);

		IRegisterDAO dao = new RegisterDAOImpl();
		int p=-1;
		try {
			p = dao.insert(register);
			if(p>=1)
			{
				resp.setHeader("Content-Type","text/html;charset=utf-8");

				resp.getWriter().print("登录成功，即将为您跳转登录页面......");
				resp.setHeader("refresh","2,url=updatePassword.html");
			}
			else
			{
				resp.getWriter().print("insert fail");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

		
		
	}
	

}
